<?php
/**
 * Created by PhpStorm.
 * User: HLG
 * Date: 2019/10/16
 * Time: 14:01
 */
namespace app\api\model;
use app\common\model\UploadFile;
use think\Request;
use think\Db;
class GoodSku extends BaseModel
{
    protected $table = 'yoshop_goods_sku';

    /**
     * 查询商品规格详情
     *
     * @param $goods_id
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getSpec($goods_id)
    {
        $spec = $this->alias('k')
            ->join('goods_spec_rel r','k.spec_sku_id=r.spec_value_id','left')
            ->join('spec s','s.spec_id=r.spec_id','left')
            ->join('spec_value v','v.spec_value_id=r.spec_value_id','left')
            ->join('upload_file f','k.image_id=f.file_id','left')
            ->where('k.goods_id',$goods_id)
            ->field('goods_sku_id,goods_price,stock_num,file_url,file_name,storage,spec_name')
            ->order('goods_price asc')
            ->select();
        $uploadFile = new UploadFile();
        foreach($spec as $k=>$v){
            $src = $uploadFile->getFilePathAttr('',$v);
            $spec[$k]['sku_img'] = $src;
        }
        return $spec;
    }
}